/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import com.google.inject.Inject;

/**
 *
 * @author think
 */
public class RealMachine implements Machine {

    private String name;
    private String os;
    private String tsProjectArchive;
    private String tsProjectPath;
    private String tsTcPath;
    private String installerPath;
    private STAFHelper stafHelper;
    private ConfigManager configManager;

    @Inject
    public RealMachine(ConfigManager configManager, STAFHelper stafHelper) {
        this.configManager = configManager;
        this.stafHelper = stafHelper;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getOs() {
        return os;
    }

    public String getTsProjectArchive() {
        return this.tsProjectArchive;
    }

    public String getTsProjectPath() {
        return this.tsProjectPath;
    }

    public String getTsTcPath() {
        return this.tsTcPath;
    }

    public boolean isStarted() {
        return stafHelper.isMachineAlive(this.getName());
    }

    public boolean getProjectArchive() {
        return stafHelper.copyFile("local", configManager.getProjectArchiveName(), this.getName(), this.getTsProjectArchive());
    }

    public boolean extractProjectArchive() {
        return stafHelper.unzip(this.getName(), this.getTsProjectArchive(), this.getTsProjectPath());
    }

    /**
     * @param os the os to set
     */
    public void setOs(String os) {
        this.os = os;
    }

    /**
     * @param tsProjectArchive the tsProjectArchive to set
     */
    public void setTsProjectArchive(String tsProjectArchive) {
        this.tsProjectArchive = tsProjectArchive;
    }

    /**
     * @param tsProjectPath the tsProjectPath to set
     */
    public void setTsProjectPath(String tsProjectPath) {
        this.tsProjectPath = tsProjectPath;
    }

    /**
     * @param tsTcPath the tsTcPath to set
     */
    public void setTsTcPath(String tsTcPath) {
        this.tsTcPath = tsTcPath;
    }

    public boolean isInfoComplete() {
        if (this.getName() == null || this.getName().trim().equals("")) {
            return false;
        }
        if (this.getTsProjectPath() == null || this.getTsProjectPath().trim().equals("")) {
            return false;
        }
        if (this.getTsProjectArchive() == null || this.getTsProjectArchive().trim().equals("")) {
            return false;
        }
        if (this.getTsTcPath() == null || this.getTsTcPath().trim().equals("")) {
            return false;
        }
        return true;
    }

    void setInstallerPath(String path) {
        this.installerPath = path;
    }

    /**
     * @return the installerPath
     */
    public String getInstallerPath() {
        return installerPath;
    }
}
